<?php
use think\facade\Route;

// admin根路径重定向
Route::get('admin', function () {
    return redirect('/admin/login');
});

// 登录相关路由（不需要认证）
Route::group(function () {
    Route::get('login', 'Login/index');
    Route::post('login', 'Login/doLogin');
    Route::get('captcha', 'Login/captcha');
    
    // Session测试路由
    Route::get('session/set', 'SessionTest/set');
    Route::get('session/get', 'SessionTest/get');
})->prefix('admin/');

// 管理后台路由组
Route::group(function () {

    // 退出登录
    Route::get('logout', 'Login/logout');

    // 仪表板
    Route::get('dashboard', 'Dashboard/index');
    Route::get('dashboard/statistics', 'Dashboard/getStatisticsApi');

    // 商户管理
    Route::group('merchant', function () {
        Route::get('/', 'Merchant/index');
        Route::get('detail/:id', 'Merchant/detail');
        Route::post('approve/:id', 'Merchant/approve');
        Route::post('reject/:id', 'Merchant/reject');
        Route::delete('delete/:id', 'Merchant/delete');
        Route::post('batch', 'Merchant/batch');
        Route::get('export', 'Merchant/export');
    });

    // 操作日志
    Route::group('log', function () {
        Route::get('/', 'Log/index');
        Route::get('detail/:id', 'Log/detail');
        Route::post('clear', 'Log/clear');
    });

    // 系统状态
    Route::group('system', function () {
        Route::get('/', 'System/index');
        Route::post('clearCache', 'System/clearCache');
    });

    // 账号管理
    Route::group('account', function () {
        Route::get('/', 'Account/index');
        Route::get('add', 'Account/add');
        Route::post('add', 'Account/doAdd');
        Route::get('edit/:id', 'Account/edit');
        Route::post('edit/:id', 'Account/doEdit');
        Route::delete('delete/:id', 'Account/delete');
        Route::post('changeStatus/:id', 'Account/changeStatus');
    });

    // 用户管理（保留原有路由）
    Route::group('user', function () {
        Route::get('/', 'User/index');
        Route::get('detail/:id', 'User/detail');
        Route::post('status/:id', 'User/changeStatus');
        Route::get('export', 'User/export');
    });

    // 系统设置（保留原有路由）
    Route::group('setting', function () {
        Route::get('/', 'Setting/index');
        Route::post('save', 'Setting/save');
        Route::get('cache', 'Setting/cache');
        Route::post('cache/clear', 'Setting/clearCache');
    });

})->prefix('admin/');
